import { Component, OnInit, Input, TemplateRef } from '@angular/core';
// import ngx-bootstrap
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef }     from 'ngx-bootstrap/modal/modal-options.class';
import { cbCfgList }      from '../../condition/condition-builder.config';


@Component({
  selector: 'app-expression-dialog',
  templateUrl: './expression-dialog.html',
  providers: [BsModalService]
})
export class ExpressionDialog implements OnInit {

  // @Input() condtionDetail: any[];
  public title: string;
  public conditionDetailList: any[] = [];
  public expressionDetail:    any[] = [];

  public expressionData:     any[] = [];


  private conditionExpressionDetail = new Array();

  constructor(
    public bsModalRef: BsModalRef
  ) { }

  public expressionValues =new Array();


  ngOnInit() {
    // console.log(this.conditionDetailList, '---');
  }

  public showExpressionModal(data: any) {
    this.expressionData = data;
    console.log('--- expression data from expression component ---', this.expressionData);
    for (let i = 0; i < cbCfgList.length; i ++) {
      for (let j = 0; j < this.expressionData.length; j++) {
        if (cbCfgList[i].id == this.expressionData[j].id) {
          this.expressionValues.push({
            "title":     cbCfgList[i].title,
            "condition": cbCfgList[i].condition,
            "shortcut":  cbCfgList[i].shortcut,
            "value":     this.expressionData[j].value,
            "operator":  this.expressionData[j].operation,
            "component": this.expressionData[j].component
          })
        }
      }
    }
  }


}
